﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Air_condition.DO;
using System.Reflection;
using System.Threading;
using System.Windows.Media.Animation;

namespace Report
{
    /// <summary>
    /// Interaction logic for CalculateReport.xaml
    /// </summary>
    public partial class CalculateReport : Window
    {
        public CalculateReport()
        {
            InitializeComponent();
        }

        public bool LoadAlternative(List<Alternative> la)
        {
            lstAltList.Items.Clear();
            foreach (Alternative alt in la)
            {
                if (alt.lRoom.Count != 0)
                {
                    lstAltList.Items.Add(alt);
                }
            }
            if (lstAltList.Items.Count == 0)
            {
                return false;
            }
            return true;
        }

        private void btnCalculate_Click(object sender, RoutedEventArgs e)
        {
            Thread thread = new Thread(new ThreadStart(startloading));
            thread.SetApartmentState(ApartmentState.STA);
            thread.IsBackground = true;
            thread.Start();

            Report.MainReport mr = new Report.MainReport();
            mr.LoadCrystalAir();
            thread.Abort();
            foreach (object a in lstAltList.SelectedItems)
            {
                ((Alternative)a).CalculationSumColdProductivity();
                mr.LoadTreeView((Alternative)a);
            }
            if (lstAltList.SelectedItems.Count != 0)
            {                
                mr.ShowDialog();                
            }
            else
            {
                MessageBox.Show("Please select alternative!");
            }
            
        }
        public void startloading()
        {
            Loading.MainWindow loading = new Loading.MainWindow();
            loading.ShowDialog();
            System.Windows.Threading.Dispatcher.Run();
        }
    }
}
